//
//  WSRecommendCell.m
//  GroupFourFM
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 GroupFour. All rights reserved.
//

#import "WSRecommendCell.h"
#import "WSContentCell.h"

@interface WSRecommendCell ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, strong) UICollectionView *collectionV;

@end

@implementation WSRecommendCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return self;
}

- (void)createSubView {
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
    flowLayout.minimumLineSpacing = 15;
    flowLayout.itemSize = CGSizeMake((SCREEN_WIDTH - 60) / 3,(SCREEN_WIDTH - 60) / 3 + 50);
    
    self.collectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:flowLayout];
    self.collectionV.delegate = self;
    self.collectionV.dataSource = self;
    self.collectionV.backgroundColor = WHITE;
    [self.contentView addSubview:_collectionV];
    [self.collectionV registerClass:[WSContentCell class] forCellWithReuseIdentifier:@"cell"];
    
    [self.collectionV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.right.mas_equalTo(@0);
        make.bottom.mas_equalTo(@(-10));
    }];
}

#pragma mark - collectionView delegate &dataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.allPicArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    WSContentCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.textModel = [self.allPicArray objectAtIndex:indexPath.row];
    
    return cell;
}

- (void)setAllPicArray:(NSMutableArray *)allPicArray {

    _allPicArray = allPicArray;
    [self.collectionV reloadData];
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    WSChildListModel *model = [self.allPicArray objectAtIndex:indexPath.row];

    [self.delegate JumpToAlbumView:model.albumId title:self.title];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
